package com.chenfan.mcn.extension.excel;

import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import com.chenfan.mcn.model.vo.StarSignContractExportVO;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.CreationHelper;

import java.util.Objects;

/**
 * @author wulg
 * @date 2023/10/23
 */
public class EnhancedExcelDataHandler extends ExcelDataHandlerDefaultImpl<Object> {

    @Override
    public Hyperlink getHyperlink(CreationHelper creationHelper, Object obj, String name, Object value) {

        if(Objects.isNull(value)) {
            return null;
        }
        if(StringUtils.isBlank(value.toString())) {
            return null;
        }
        Hyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
        //暂时没有更好的方法处理
        if(obj instanceof StarSignContractExportVO) {
            StarSignContractExportVO vo = (StarSignContractExportVO)obj;
            if("合同一".equals(name)) {
                hyperlink.setLabel(vo.getContract1());
                if(StringUtils.isNotBlank(vo.getAddress1())) {
                    hyperlink.setAddress(vo.getAddress1());
                }
            } else if("合同二".equals(name)) {
                hyperlink.setLabel(vo.getContract2());
                if(StringUtils.isNotBlank(vo.getAddress2())) {
                    hyperlink.setAddress(vo.getAddress2());
                }
            } else if("合同三".equals(name)) {
                hyperlink.setLabel(vo.getContract3());
                if(StringUtils.isNotBlank(vo.getAddress3())) {
                    hyperlink.setAddress(vo.getAddress3());
                }
            } else if("合同四".equals(name)) {
                hyperlink.setLabel(vo.getContract4());
                if(StringUtils.isNotBlank(vo.getAddress4())) {
                    hyperlink.setAddress(vo.getAddress4());
                }
            } else if("合同五".equals(name)) {
                hyperlink.setLabel(vo.getContract5());
                if(StringUtils.isNotBlank(vo.getAddress5())) {
                    hyperlink.setAddress(vo.getAddress5());
                }
            }
        }
        return hyperlink;
    }
}
